<?php echo $this->render('/public/header'); ?>
<?php use yii\widgets\LinkPager; ?>
<script src="https://cdn.bootcss.com/element-ui/2.0.11/index.js"></script>
<link href="https://cdn.bootcss.com/element-ui/2.0.11/theme-chalk/index.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-datepicker/1.7.1/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<link href="https://cdn.bootcss.com/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker.min.css" rel="stylesheet">
<script src="/statics/public/postbird-img-glass.js"></script>
<div id="main" class="col-xs-12">
    <form method="get">
        <div class="form-inline">
            <div class="form-group">
                <select class="form-control" name="job_number">
                    <option value="0">业务员选择</option>
                    <?php foreach ($this->params['staff'] as $v): ?>
                        <option value="<?php echo $v['job_number']; ?>" <?php echo $v['job_number'] == (yii::$app->request->get('job_number')) ? 'selected' : "" ?>><?php echo $v['name']; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="form-group">
                <select class="form-control" name="status">
                    <option value="0">审核状态选择</option>
                    <option value="1" <?php echo 1 == (yii::$app->request->get('status')) ? 'selected' : "" ?>>未审核
                    </option>
                    <option value="2" <?php echo 2 == (yii::$app->request->get('status')) ? 'selected' : "" ?>>审核通过
                    </option>
                    <option value="3" <?php echo 3 == (yii::$app->request->get('status')) ? 'selected' : "" ?>>审核失败
                    </option>
                </select>
            </div>
            <div class="form-group">
                <select name="type" class="form-control">
                    <option value="0">性质</option>
                    <option value="1" <?php if (yii::$app->request->get('type') == 1) {
                        echo 'selected';
                    } ?>>大货
                    </option>
                    <option value="2" <?php if (yii::$app->request->get('type') == 2) {
                        echo 'selected';
                    } ?>>样品
                    </option>
                    <option value="3" <?php if (yii::$app->request->get('type') == 3) {
                        echo 'selected';
                    } ?>>其他
                    </option>
                </select>
            </div>
            <div class="form-group">
                <select name="type2" class="form-control">
                    <option value="0">类型</option>
                    <option value="1" <?php if (yii::$app->request->get('type2') == 1) {
                        echo 'selected';
                    } ?>>样品
                    </option>
                    <option value="2" <?php if (yii::$app->request->get('type2') == 2) {
                        echo 'selected';
                    } ?>>交通(本地)
                    </option>
                    <option value="3" <?php if (yii::$app->request->get('type2') == 3) {
                        echo 'selected';
                    } ?>>快递
                    </option>
                    <option value="4" <?php if (yii::$app->request->get('type2') == 4) {
                        echo 'selected';
                    } ?>>其他
                    </option>
                    <option value="5" <?php if (yii::$app->request->get('type2') == 5) {
                        echo 'selected';
                    } ?>>差旅(外地)
                    </option>
                </select>
            </div>
            <div class="form-group">
                <input placeholder="搜索invoice" type="text" value="<?php echo yii::$app->request->get('invoice'); ?>"
                       name='invoice' class="form-control"/>
            </div>
            <div class="form-group">
                <input type="text" value="<?php echo yii::$app->request->get('begin_date'); ?>" name="begin_date"
                       placeholder="开始时间" class="form-control form-date"/>
            </div>
            <div class="form-group">
                <input type="text" value="<?php echo yii::$app->request->get('end_date'); ?>" name="end_date"
                       placeholder="结束时间" class="form-control form-date"/>
            </div>
            <button class="btn btn-success">搜索</button>
            <span class="label label-danger" style="float:right">未付款：<?php echo $money; ?></span>
        </div>
    </form>
    <br/>
    <button class="btn btn-danger" onclick="download()">下载</button>
    <br/>
    <br/>
    <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="所有审核" name="first">
            <table class="table table-borderd">
                <thead>
                <tr>
                    <th style="width:76px">登记时间</th>
                    <th style="width:76px">报销时间</th>
                    <th style="width:50px">报销申请人</th>
                    <th style="width:76px">报销金额</th>
                    <th>报销名称</th>
                    <th style="width:50px">报销数量</th>
                    <th style="width:100px">报销凭证</th>
                    <th style="width:140px">invoice</th>
                    <th>客户编号</th>
                    <th>客户全名</th>
                    <th style="width:76px">性质</th>
                    <th style="width:76px">类型</th>
                    <th>备注</th>
                    <th style="width:50px">正在处理</th>
                    <th style="width:76px">最后审核人</th>
                    <th style="width:70px">报销状态</th>
                    <th style="width:100px">打款操作人</th>
                    <th style="width:100px">打款时间</th>
                    <th style="width:250px">操作</th>
                </tr>
                </thead>
                <?php foreach ($this->params['list'] as $v) : ?>
                    <?php $detail = json_decode($v['detail'], true); ?>
                    <tr>
                        <td><?php echo $v['create_at'] ?></td>
                        <td><?php echo $v['time'] ? date('Y-m-d', $v['time']) : ''; ?></td>
                        <td>
                            <?php foreach ($this->params['staff'] as $v2): ?>
                                <?php if ($v2['job_number'] == $v['job_number']): ?>
                                    <?php echo $v2['name']; ?>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </td>
                        <td><?php echo $detail['fee']; ?></td>
                        <td><?php echo $detail['name']; ?></td>
                        <td><?php echo $detail['number']; ?></td>
                        <td>
                            <div class="glass-img"><?php if (!empty($detail['img'])) {
                                    foreach ($detail['img'] as $v2) {
                                        echo "<img src='" . $v2 . "' style='width:100px;height:100px'/>";
                                    }

                                }; ?></div>
                        </td>
                        <td>
                            <input onchange="update(<?php echo $v['id']; ?>,'invoice',this.value)" type="text"
                                   class="form-control" value="<?php echo $v['invoice']; ?>"/>
                        </td>
                        <td>
                            <input onchange="update(<?php echo $v['id']; ?>,'customer_num',this.value)" type="text"
                                   class="form-control" value="<?php echo $v['customer_num']; ?>"/>
                        </td>
                        <td><?php echo $v['customer_name']; ?></td>
                        <td>
                            <?php if ($v['type'] == 1) {
                                echo '大货';
                            } elseif ($v['type'] == 2) {
                                echo '样品';
                            } elseif ($v['type'] == 3) {
                                echo '其他';
                            }; ?>
                        </td>
                        <td><?php
                            if ($v['type2'] == 1) {
                                echo '样品';
                            }
                            if ($v['type2'] == 2) {
                                echo '交通(本地)';
                            }
                            if ($v['type2'] == 3) {
                                echo '快递';
                            }
                            if ($v['type2'] == 4) {
                                echo '其他';
                            }
                            if ($v['type2'] == 5) {
                                echo '差旅(外地)';
                            }

                            ?></td>
                        <td><?php echo $detail['remark'] ?? '' ; ?></td>
                        <td><?php echo $v['current_verify'] == 2 ? '朱竞' : '财务'; ?></td>
                        <td>
                            <?php foreach ($this->params['staff'] as $v2): ?>
                                <?php if ($v2['job_number'] == $v['verify_staff']): ?>
                                    <?php echo $v2['name']; ?>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </td>
                        <td><?php if ($v['status'] == 1) {
                                echo '<span class=\'label label-info\'>未审核</span>';
                            }
                            if ($v['status'] == 2) {
                                echo '<span class=\'label label-success\'>审核通过</span>';
                            }
                            if ($v['status'] == 3) {
                                echo '<span class=\'label label-danger\'>审核失败</span>';
                            } ?></td>
                        <td>
                            <?php foreach ($this->params['staff'] as $v2): ?>
                                <?php if ($v2['job_number'] == $v['pay_staff']): ?>
                                    <?php echo $v2['name']; ?>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </td>
                        <td><?php echo $v['pay_time'] > 0 ? date('Y-m-d H:i:s', $v['pay_time']) : ''; ?></td>
                        <td>
                            <a href="javascript:upload(<?php echo $v['id']; ?>,2)" class="btn btn-success">审核通过</a>
                            <a href="javascript:upload(<?php echo $v['id']; ?>,3)" class="btn btn-danger">拒绝</a>
                            <button class="btn btn-primary" onclick="updateVerifyStaff(<?php echo $v['id']; ?>)">审核转交
                            </button>
                            <button class="btn btn-danger" onclick="del(<?php echo $v['id']; ?>)">删除</button>
                            <button class="btn btn-warning" onclick="updatePay(<?php echo $v['id']; ?>)">确认打款</button>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
            <?php echo LinkPager::widget(['pagination' => $page]); ?>
        </el-tab-pane>
        <el-tab-pane label="我的审核" name="second">
            <table class="table table-borderd">
                <thead>
                <tr>
                    <th style="width:76px">登记时间</th>
                    <th style="width:76px">报销时间</th>
                    <th style="width:50px">报销申请人</th>
                    <th style="width:76px">报销金额</th>
                    <th>报销名称</th>
                    <th style="width:50px">报销数量</th>
                    <th style="width:100px">报销凭证</th>
                    <th style="width:120px">invoice</th>
                    <th>客户编号</th>
                    <th>客户全名</th>
                    <th style="width:76px">性质</th>
                    <th style="width:76px">类型</th>
                    <th>备注</th>
                    <th style="width:50px">正在处理</th>
                    <th style="width:76px">最后审核人</th>
                    <th style="width:70px">报销状态</th>
                    <th style="width:100px">打款操作人</th>
                    <th style="width:100px">打款时间</th>
                    <th style="width:250px">操作</th>
                </tr>
                </thead>
                <?php foreach ($list2 as $v) : ?>
                    <?php $detail = json_decode($v['detail'], true); ?>
                    <tr>
                        <td><?php echo $v['create_at'] ?></td>
                        <td><?php echo $v['time'] ? date('Y-m-d', $v['time']) : ''; ?></td>
                        <td>
                            <?php foreach ($this->params['staff'] as $v2): ?>
                                <?php if ($v2['job_number'] == $v['job_number']): ?>
                                    <?php echo $v2['name']; ?>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </td>
                        <td><?php echo $detail['fee']; ?></td>
                        <td><?php echo $detail['name']; ?></td>
                        <td><?php echo $detail['number']; ?></td>
                        <td>
                            <div class="glass-img"><?php if (!empty($detail['img'])) {
                                    foreach ($detail['img'] as $v2) {
                                        echo "<img src='" . $v2 . "' style='width:100px;height:100px'/>";
                                    }

                                }; ?></div>
                        </td>
                        <td>
                            <input onchange="update(<?php echo $v['id']; ?>,'invoice',this.value)" type="text"
                                   class="form-control" value="<?php echo $v['invoice']; ?>"/>
                        </td>
                        <td>
                            <input onchange="update(<?php echo $v['id']; ?>,'customer_num',this.value)" type="text"
                                   class="form-control" value="<?php echo $v['customer_num']; ?>"/>
                        </td>
                        <td><?php echo $v['customer_name']; ?></td>
                        <td>
                            <?php if ($v['type'] == 1) {
                                echo '大货';
                            } elseif ($v['type'] == 2) {
                                echo '样品';
                            }; ?>
                        </td>
                        <td><?php
                            if ($v['type2'] == 1) {
                                echo '样品';
                            }
                            if ($v['type2'] == 2) {
                                echo '交通(本地)';
                            }
                            if ($v['type2'] == 3) {
                                echo '快递';
                            }
                            if ($v['type2'] == 4) {
                                echo '其他';
                            }
                            if ($v['type2'] == 5) {
                                echo '差旅(外地)';
                            }

                            ?></td>
                        <td><?php echo $detail['remark']??""; ?></td>
                        <td><?php echo $v['current_verify'] == 2 ? '朱竞' : '财务'; ?></td>
                        <td>
                            <?php foreach ($this->params['staff'] as $v2): ?>
                                <?php if ($v2['job_number'] == $v['verify_staff']): ?>
                                    <?php echo $v2['name']; ?>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </td>
                        <td><?php if ($v['status'] == 1) {
                                echo '<span class=\'label label-info\'>未审核</span>';
                            }
                            if ($v['status'] == 2) {
                                echo '<span class=\'label label-success\'>审核通过</span>';
                            }
                            if ($v['status'] == 3) {
                                echo '<span class=\'label label-danger\'>审核失败</span>';
                            } ?></td>
                        <td>
                            <?php foreach ($this->params['staff'] as $v2): ?>
                                <?php if ($v2['job_number'] == $v['pay_staff']): ?>
                                    <?php echo $v2['name']; ?>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </td>
                        <td><?php echo $v['pay_time'] > 0 ? date('Y-m-d H:i:s', $v['pay_time']) : ''; ?></td>
                        <td>
                            <a href="javascript:upload(<?php echo $v['id']; ?>,2)" class="btn btn-success">审核通过</a>
                            <a href="javascript:upload(<?php echo $v['id']; ?>,3)" class="btn btn-danger">拒绝</a>
                            <button class="btn btn-primary" onclick="updateVerifyStaff(<?php echo $v['id']; ?>)">审核转交
                            </button>
                            <button class="btn btn-danger" onclick="del(<?php echo $v['id']; ?>)">删除</button>
                            <button class="btn btn-warning" onclick="updatePay(<?php echo $v['id']; ?>)">确认打款</button>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
            <?php echo LinkPager::widget(['pagination' => $page]); ?>
        </el-tab-pane>
    </el-tabs>

</div>
<script>
    new Vue({
        el: "#main",
        data: {
            activeName: 'second'
        },
        mounted() {
            PostbirdImgGlass.init({
                domSelector: ".glass-img img",
                animation: true,
                width: "700px",
                height: "500px",
            });
        },
        methods: {
            handleClick(tab, event) {
                console.log(tab, event);
            }
        }
    });
    $(function () {
        $('.form-date').datepicker({"format": "yyyy-mm-dd"});
    });

    function updateVerifyStaff(id) {
        layer.confirm('确认将次报销单转给管理员', {}, function () {
            $.post('/finance/update-verify-staff', {id: id}, function (res) {
                if (res.code == 1) {
                    layer.alert(res.msg);
                    setTimeout(function () {
                        window.lcoation.reload();
                    }, 1000)
                } else {
                    layer.alert(res.msg);
                }
            }, 'json')
        })
    }

    function upload(id, status) {
        layer.confirm('确认修改', {}, function () {
            var url = '/finance/reimburse_edit';
            $.post(url, {id: id, status: status}, function (res) {
                if (res.code == 1) {
                    layer.confirm(res.msg, {}, function () {
                        window.location.reload();
                    })
                } else {
                    layer.alert(res.msg);
                }
            }, 'json')
        });
    }

    function del(id) {
        layer.confirm('确认删除', {}, function () {
            $.post('/finance/del-baoxiao', {id: id}, function (res) {
                layer.alert(res.msg);
                if (res.code == 1) {
                    setTimeout(function () {
                        window.location.reload()
                    }, 1000);
                }
            }, 'json')
        })
    }

    function update(id, param, value) {
        layer.confirm('确认修改', {}, function () {
            $.post('/finance/reimburse-update', {id: id, param: param, value: value}, function (res) {
                layer.alert(res.msg);
                setTimeout(function () {
                    window.location.reload();
                }, 1000)
            }, 'json')
        })
        console.log(id, param, value);
    }

    function updatePay(id) {
        layer.confirm('确认打款', {}, function () {
            $.post('/finance/update-pay', {id: id}, function (res) {
                layer.alert(res.msg);
                setTimeout(function () {
                    window.location.reload();
                }, 1000)
            }, 'json')
        })
    }

    function download() {
        window.location.href = "/download/reimburse" + window.location.search;
    }
</script>
<?php echo $this->render('/public/footer'); ?>
